package com.goldgov.synchronous.web;

import java.text.SimpleDateFormat;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.synchronous.service.ConferenceSynchronousService;
import com.goldgov.synchronous.service.FlowLearnSynchronousService;

import io.swagger.annotations.Api;

@RestController
@RequestMapping("/workbench/synchronous/syncConferenceStatistics")
@Api("数据统计同步接口")
public class SyncConferenceStatisticsWeb {
	Log logger = LogFactory.getLog(getClass());
	
	
	@Autowired
	private ConferenceSynchronousService conferenceSynchronousService;
	@Autowired
	private FlowLearnSynchronousService flowLearnSynchronousService;
	
	@Scheduled(cron="0 0 0/6 * * ?")//每隔6小时执行一次
	//@Scheduled(cron="0 0 1 * * ?")//每天凌晨一点
	//@Scheduled(cron="0/50 * * * * ?")//测试用每隔五十秒执行
	@GetMapping("/syncInfo")
	 public synchronized void syncInfo() throws Exception{
		SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		String datetime = tempDate.format(new java.util.Date());  
		System.out.println(datetime+"同步三会一课统计.....");
		try {
			conferenceSynchronousService.conferenceSynchronousStoreBasicData();
		} catch (Exception e) {
			logger.error("三会一课统计同步失败");
			e.printStackTrace();
		}
	}
	
	
	@Scheduled(cron="0 0 22 ? * SAT")//每周六凌晨23点执行
	@GetMapping("/lddyxxInfo")
	public synchronized void lddyxxInfo() throws Exception{
		SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		String datetime = tempDate.format(new java.util.Date());  
		logger.info(datetime+"党员人员统计.....");
		try {
			long startTime=System.currentTimeMillis();   //获取开始时间
			flowLearnSynchronousService.lddySynchronousStoreBasicData();
			long endTime=System.currentTimeMillis(); //获取结束时间
			logger.info("党员人员统计完成用时： "+(endTime-startTime)+"ms");
		} catch (Exception e) {
			logger.error("党员人员统计同步失败");
			e.printStackTrace();
		}
	}
}
